GithubHelp home page GithubHelp logo

Comments (7)

ntorrey avatar ntorrey commented on May 13, 2024 2

Using fetch will always return the entire contents of the record link. The cool thing is that it's not necessary for your use-case. fetch is not required to pull record properties directly from a record link. So the following should give you what you need:

SELECT *, artist.email FROM review limit 1

You may need to OMIT the artist field to get exactly what you want, but I haven't tested it...

SELECT *, artist.email OMIT artist FROM review limit 1

from surrealdb.

ntorrey avatar ntorrey commented on May 13, 2024 2

What about this?

SELECT *, NONE as artist, artist.email FROM review limit 1

from surrealdb.

mindreframer avatar mindreframer commented on May 13, 2024 1

Thanks @ntorrey ! Sadly none of those queries return artist....

> SELECT *, artist.email FROM review limit 1
[
        {
                artist: artist:73z6oc419v1c5v34j20x,
                id: review:00a0ic854u4j7z02s00v,
                person: person:67s8cp304i4p6p83q02d,
                product: product:41v2qv923h3o7s55e96l,
                rating: 3,
                review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange m
eter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
        }
]


> SELECT *, artist.email OMIT artist FROM review limit 1
[
        {
                id: review:00a0ic854u4j7z02s00v,
                person: person:67s8cp304i4p6p83q02d,
                product: product:41v2qv923h3o7s55e96l,
                rating: 3,
                review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange m
eter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
        }
]

Hence the bug report...

from surrealdb.

mindreframer avatar mindreframer commented on May 13, 2024 1

@ntorrey Nice, that one works! :)

> SELECT *, NONE as artist, artist.email FROM review limit 1
[
        {
                artist: {
                        email: '[email protected]'
                },
                id: review:00a0ic854u4j7z02s00v,
                person: person:67s8cp304i4p6p83q02d,
                product: product:41v2qv923h3o7s55e96l,
                rating: 3,
                review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange m
eter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
        }
]

Awesome! Still, I consider this a workaround, that is non-obvious. I'll be using it for now, let's hope this gets fixed in future.

Thanks, you have saved me writing lots of gnarly "select"-generating code with explicit field listing!

from surrealdb.

mindreframer avatar mindreframer commented on May 13, 2024 1

@ntorrey Great trick!
About feature request: I feel SurrealDB team is quite overloaded and I'd rather have them focusing on performance improvements and bug fixes.

Also the SQL statement that I have used is directly from the documentation, so that is why it is a bug report. I'm happy if the documented specs match the actual implementation. But yeah, have a great day, @ntorrey, this is a life-saving trick :)

from surrealdb.

ntorrey avatar ntorrey commented on May 13, 2024

Awesome! I learned that trick a while back! Although I think there might be something to your idea: to be able to write:

SELECT *, artist.email FROM review limit 1 FETCH artist;

Does seem more intuitive.
Or maybe Surreal should just be smart enough to infer what is desired here:

SELECT *, artist.email FROM review limit 1

(Automatically replacing the artist record link with artist.email)
Maybe a good feature request?

from surrealdb.

cscetbon avatar cscetbon commented on May 13, 2024

Agreed, I just stomped on it yesterday and was going to file a bug. I've also noticed that aliasing allows to get the email when not aliasing doesn't ...

test/test> SELECT *, artist.email FROM review limit 1;
-- Query 1 (execution time: 314.25µs)
[
    {
        artist: artist:73z6oc419v1c5v34j20x,
        id: review:00a0ic854u4j7z02s00v,
        person: person:67s8cp304i4p6p83q02d,
        product: product:41v2qv923h3o7s55e96l,
        rating: 3,
        review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange meter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
    }
]
test/test> SELECT *, artist.email as artist_email FROM review limit 1;
-- Query 1 (execution time: 907.167µs)
[
    {
        artist: artist:73z6oc419v1c5v34j20x,
        artist_email: '[email protected]',
        id: review:00a0ic854u4j7z02s00v,
        person: person:67s8cp304i4p6p83q02d,
        product: product:41v2qv923h3o7s55e96l,
        rating: 3,
        review_text: 'repeat languages tr rest hospital consulting infrastructure melissa proposal singing finally hey eggs left market title yards identify movement themselves existing lake questions exchange meter strip up archive interview rather mostly transit stuff attitude fundamental palestinian estate cast yours eye lawyer academy sunset holy gang'
    }
]

But then the format you get is different, so I totally agree that it's a bug that needs to be fixed

from surrealdb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.