Guest User

Untitled

a guest
Dec 17th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. ## Is the `bigserial` compatible with the `bigint` on Cockroach?
  2.  
  3.  
  4. ### Create the tables
  5. Let's create **table_x** with a `bigserial` column and set it as the `primary key`.
  6.  
  7. ```sql
  8. CREATE TABLE table_x (
  9. id bigserial PRIMARY KEY,
  10. whatever text
  11. );
  12. ```
  13.  
  14.  
  15. Now we create the **table_y** but set it's columns to `bigint`, but no `primary key` this time _(this should not interfere in anything)_:
  16. ```sql
  17. CREATE TABLE table_y (
  18. table_x_id bigint,
  19. whatever text
  20. );
  21. ```
  22.  
  23. ### load data
  24. Let's insert some data on the tables and try to compare the values:
  25.  
  26. ```sql
  27. INSERT INTO table_x(id, whatever) values (1000000000009, 'name 1'), (200000000000000009, 'name 2');
  28. ```
  29.  
  30.  
  31. ```sql
  32. INSERT INTO table_y(id, whatever) values (1000000000009, 'name 1'), (200000000000000009, 'name 2');
  33. ```
  34.  
  35. ### Compare the values
  36.  
  37. ```sql
  38. select
  39. id,
  40. table_x.whatever as whatever,
  41. (table_x.id = table_y.table_x_id) as is_equal
  42. from
  43. table_x as table_x
  44.  
  45. left join table_y as table_y
  46. on table_y.table_x_id = table_x.id
  47. ```
  48.  
  49. Result
  50.  
  51. ```
  52. id | whatever | is_equal
  53. +--------------------+----------+----------+
  54. 1000000000009 | name 1 | true
  55. 200000000000000009 | name 2 | true
  56. (2 rows)
  57.  
  58. Time: 4.427524ms
  59. ```
  60.  
  61. ### Conclusion
  62.  
  63. I guess it is safe to say that for LEFT JOINs (and probably the other JOINs as well) both types are compatible.
Add Comment
Please, Sign In to add comment